package com.gohome.gohomechat.ui.activity;

import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.gohome.gohomechat.GoHomeHelper;
import com.gohome.gohomechat.GoHomeModel;
import com.gohome.gohomechat.R;
import com.gohome.gohomechat.db.GoHomeDBTools;
import com.gohome.gohomechat.model.entify.CurrentUser;
import com.gohome.gohomechat.presenter.PersonalPresenter;
import com.gohome.gohomechat.presenter.presenterlistener.PersonalPresenterInterface;
import com.gohome.gohomechat.ui.viewlistener.PersonalViewInterface;
import com.gohome.gohomechat.utils.ToActivityUtil;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by dllo on 16/3/8.
 */
public class PersonalActivity extends BaseActivity implements PersonalViewInterface, View.OnClickListener {
    private ImageView personal_head;
    private TextView personal_username, personal_nick, personal_singnature, personal_birthday, personal_sex, personal_age, personal_zodiaz, personal_boold, personal_email, personal_title_editor;
    private ImageButton personal_imgbtn_back;
    private PersonalPresenterInterface personalPresenterInterface;

    @Override
    protected int getLayout() {
        return R.layout.activity_personal;
    }

    @Override
    protected void initPresenter() {
        personalPresenterInterface=new PersonalPresenter(this);
    }

    @Override
    protected void initView() {
        personal_head = findView(R.id.personal_head);
        personal_username = findView(R.id.personal_username);
        personal_nick = findView(R.id.personal_nick);
        personal_singnature = findView(R.id.personal_singnature);
        personal_birthday = findView(R.id.personal_birthday);
        personal_sex = findView(R.id.personal_sex);
        personal_age = findView(R.id.personal_age);
        personal_zodiaz = findView(R.id.personal_zodiaz);
        personal_boold = findView(R.id.personal_boold);
        personal_email = findView(R.id.personal_email);
        personal_title_editor = findView(R.id.personal_title_editor);
        personal_imgbtn_back = findView(R.id.personal_imgbtn_back);



    }

    @Override
    protected void initData() {
     //   personalPresenterInterface.loadData();
        List<CurrentUser> currentUsers=GoHomeDBTools.getInstance().queryAllDatas_personal();

        showInfo(currentUsers.get(currentUsers.size()-1));

        personal_imgbtn_back.setOnClickListener(this);
        personal_title_editor.setOnClickListener(this);
    }

    @Override
    public void showDialog() {
        showProgressDialog();
    }

    @Override
    public void dismissDialog() {
        dismissDialog();
    }

    @Override
    public void showInfo(CurrentUser user) {

        Picasso.with(this).load(user.getHead()).into(personal_head);
        personal_username.setText("用户名: " + GoHomeModel.getInstance().getCurrentUserName());
        personal_nick.setText("昵称: " + user.getNick());
        personal_singnature.setText("个性签名: " + user.getSingnature());
        personal_birthday.setText("生日: " + user.getBirthday());
        personal_sex.setText("性别: " + user.getSex());
        personal_age.setText("年龄: " + user.getAge());
        personal_zodiaz.setText("生肖: " + user.getZodiaz());
        personal_boold.setText("血型: " + user.getBoold());
        personal_email.setText("邮箱: " + user.getEmail());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.personal_imgbtn_back: // 返回
                finish();
                break;
            case R.id.personal_title_editor: //编辑
                ToActivityUtil.startToActivity(this, EditorDataActivity.class);
                finish();
                break;
        }
    }

    @Override
    protected void onResume() {
        personal_head.setImageBitmap(GoHomeHelper.getInstance().getCurrentUserHead());
        super.onResume();
    }
}
